package cn.yyh.mq.runner;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class SendMQRunner implements CommandLineRunner {

	@Autowired
	private RabbitTemplate rabbitTemplate;

	@Override
	public void run(String... args) throws Exception {
		rabbitTemplate.convertAndSend("topicExchange", "queue.foo", new Teacher(27, "阳永衡"));
		rabbitTemplate.convertAndSend("topicExchange", "queue.bar", new Student(23, "许慧燕"));
		rabbitTemplate.convertAndSend("fanoutExchange", "", new Teacher(27, "阳永衡"));
	}
}

class Person {
	private int age;
	private String name;

	public Person() {
		super();
	}

	public Person(int age, String name) {
		super();
		this.age = age;
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Person [age=" + age + ", name=" + name + "]";
	}

}

class Teacher extends Person {

	public Teacher() {
		super();
	}

	public Teacher(int age, String name) {
		super(age, name);
	}
}

class Student extends Person {

	public Student() {
		super();
	}

	public Student(int age, String name) {
		super(age, name);
	}
}